use core::ffi::c_void;
use core::ptr::null_mut;

use cmsis_rtos2::thread::Thread;
use cmsis_rtos2::{osPriority_t_osPriorityHigh, osThreadDetached, os_delay, os_kernel_get_tick_count};
use log::debug;
use rtt_target::rprintln;

use crate::driver::uart;

use super::{test_task, uart_recv_task};

static mut APP_TASK: Thread<2048, osThreadDetached, osPriority_t_osPriorityHigh> =
    Thread::const_new();

extern "C" fn task(_: *mut c_void) {
    uart::init();

    test_task::start();
    uart_recv_task::start();

    loop {
        rprintln!("task run:{}", os_kernel_get_tick_count());
        debug!("app_task: {}", os_kernel_get_tick_count());
        os_delay(500);
    }
}

pub fn start() {
    unsafe {
        APP_TASK.start("app_task", task, null_mut());
    }
}
